package com.xseagull.scm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xseagull.scm.common.ResultData;
import com.xseagull.scm.dao.UserDao;
import com.xseagull.scm.entity.User;
import com.xseagull.scm.feign.AccountFeignClient;
import com.xseagull.scm.service.IUserService;

import io.seata.spring.annotation.GlobalTransactional;

@Service
public class UserService implements IUserService {

	@Autowired
	private UserDao userDao;
	
	@Autowired
	private AccountFeignClient accountFeignClient;

	@Override
	@GlobalTransactional()
	public ResultData insert(User user) {
		accountFeignClient.insert(user);
		//userDao.insert(user);
		boolean flag = true;
		if (flag) {
			throw new RuntimeException("账户或库存不足,执行回滚");
		}
		return ResultData.success(null);
	}

	@Override
	public ResultData update(User user) {
		userDao.update(user);
		return ResultData.success(null);
	}

	@Override
	public ResultData getOneParameter(int number) {
		return accountFeignClient.getOneParameter(number);
	}

	@Override
	public ResultData getMoreParameter(int number, String name) {
		return accountFeignClient.getMoreParameter(number, name);
	}

	@Override
	public ResultData getPathVariable(int number) {
		return accountFeignClient.getPathVariable(number);
	}
	
	@Override
	public ResultData postOneParameter(int number) {
		return accountFeignClient.postOneParameter(number);
	}

	@Override
	public ResultData postMoreParameter(int number, String name) {
		return accountFeignClient.postMoreParameter(number, name);
	}

	@Override
	public ResultData postPathVariable(int number) {
		return accountFeignClient.postPathVariable(number);
	}

	@Override
	public ResultData postObject(User user) {
		return accountFeignClient.postObject(user);
	}
}
